package pack0902;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public class DemoB {
    public static void main(String[] args) {
        try {
            URL ur1 = new URL("http://www.baidu.com");
            URLConnection urlConnection = ur1.openConnection();
            HttpURLConnection connection = null;
            connection = (HttpURLConnection)urlConnection;
            InputStreamReader reader = new InputStreamReader(connection.getInputStream());
            BufferedReader in = new BufferedReader(reader);
            String str = "";
            String current;
            //readLine() 从此文件读取文本的下一行。此方法可以从该文件的当前文件指针处成功地读取字节，
            // 直到到达行结束符或文件的末尾。每个字节都转换为一个字符，方法是采用该字符的低八位字节值，
            // 并将该字符的高八位设置为零。因此，此方法不支持完整的 Unicode 字符集。
            while ((current = in.readLine())!=null){
                str += current+"\n";
            }
            System.out.println(str);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
}
